package com.tengju.user.infrastructure.repository.convert;

import com.tengju.user.domain.model.club.Zone;
import com.tengju.user.domain.model.club.ZoneId;
import com.tengju.user.domain.shared.IdObject;
import com.tengju.user.infrastructure.persistence.mybatis.dataobject.ZoneDO;

import java.util.Optional;


public class ZoneConvert {

    public static ZoneDO convert(Zone zone) {
        if (zone == null) {
            return null;
        }
        ZoneDO zoneDO = new ZoneDO();
        zoneDO.setId(Optional.ofNullable(zone.getZoneId()).map(IdObject::getValue).orElse(null));
        zoneDO.setName(zone.getName());
        zoneDO.setHeadImg(zone.getHeadImg());
        zoneDO.setCreateBy(zone.getCreateBy());
        zoneDO.setUpdateBy(zone.getUpdateBy());

        return zoneDO;
    }

    public static Zone convert(ZoneDO zoneDO) {
        if (zoneDO == null) {
            return null;
        }

        return new Zone(new ZoneId(zoneDO.getId()),
                zoneDO.getName(),
                zoneDO.getHeadImg(),
                zoneDO.getCreateBy(),
                zoneDO.getUpdateBy(),
                zoneDO.getUpdateTime().toInstant().atZone(java.time.ZoneId.systemDefault()).toLocalDateTime());
    }
}
